package com.cqjtu.store.user.controller;

import com.cqjtu.store.common.R;
import com.cqjtu.store.user.pojo.dto.UserLogDTO;
import com.cqjtu.store.user.pojo.dto.UserRegDTO;
import com.cqjtu.store.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @ProjectName: cqjtu-store
 * @Titile: UserController
 * @Author: Lucky
 * @Description: 用户控制类
 */
@RestController
@RequestMapping("user") //一级
@Slf4j
@Api(tags = "用户模块")
public class UserController {
    @Autowired
    private UserService userService;
    // localhost:port/user/reg
    @PostMapping("reg")//二级
    @ApiOperation("用户注册接口")
    public R<Void> register(@RequestBody @Validated UserRegDTO userRegDTO){
        log.debug("用户注册信息：{}",userRegDTO);
        userService.register(userRegDTO);
        return R.ok();
    }

    @PostMapping("login")//二级
    @ApiOperation("用户登录接口")
    public R<Void> login(@RequestBody @Validated UserLogDTO userLogDTO){
        log.debug("用户登录信息：{}",userLogDTO);
        userService.login(userLogDTO);
        return R.ok();
    }
}
